-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(upgrade): need to call markForCheck on child changeDetectorRef #22209
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
f8df96a
to
cdc9296
Compare
@@ -139,6 +141,7 @@ export class DowngradeComponentAdapter { | |||
(<OnChanges>this.component).ngOnChanges(inputChanges !); | |||
} | |||
|
|||
this.childComponentChangeDetector.markForCheck(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the existing change detector: this.changeDetector.markForCheck();
And I suppose you need a unit test for this change as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values of this.componentRef.injector.get(ChangeDetectorRef) and this.componentRef.changeDetectorRef are not the same, and calling markForCheck on the this.changeDetector does not fix my bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, oddly this.changeDetector is not the wrapped component's actual change detector. Calling markForCheck on it has no effect (at least as far as this issue is concerned).
Looks good given my limited understanding of ngupgrade internals. Would probably need a test too (do you need help with that?). @gkalpak can you take an expert look at this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable, but we do need some tests 😁
(LMK if you need help with that.)
@@ -60,6 +61,7 @@ export class DowngradeComponentAdapter { | |||
|
|||
this.componentRef = | |||
this.componentFactory.create(childInjector, projectableNodes, this.element[0]); | |||
this.childComponentChangeDetector = this.componentRef.injector.get(ChangeDetectorRef); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really the child's ChangeDetector
? I would actually think it is the component's ChangeDetector
(or rather the ChangeDetector
of the View
within which this component resides). But I could be wrong 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the same instance that is injected into the wrapped component. So whatever that is.
BTW, I suspect this is related to #14286 (in the sense that the underlying issue is the same/similar). In which case, this comment (ignore the associated commit) would explain what is going on. I am not sure I understand the usecase, so having a failing testcase or a demo would help. |
The specific issue we encountered was with the [disabled] attribute of MatCheckbox not updating properly. One possibly confounding factor is that it is a property setter that sets the value of _disabled which is what the component actually uses. But that said, when we tried to reproduce the issue in a pure Angular (5) setting, it worked fine. |
Are you using |
I added a test case that fails when the change I added is removed. |
Take a look at the unit test for a repro. I think this issues applies to both versions of ngupgrade, but we were using full when we encountered it. |
2466e86
to
8f2b675
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also fixes #14286 afaict.
8f2b675
to
744be99
Compare
Other than the CLA issue (and g3 sync), this is ready to go. |
Hi @smdunn! This PR has merge conflicts due to recent upstream merges. |
2 similar comments
Hi @smdunn! This PR has merge conflicts due to recent upstream merges. |
Hi @smdunn! This PR has merge conflicts due to recent upstream merges. |
Seems like something went wrong. There are 141 commits on this PR now 😕 |
9d8ceeb
to
72a319c
Compare
I fixed it up (and also renamed As soon as CI is green, I'll mark the PR for merge. |
Thanks for all the help with my first angular pull request @gkalpak |
Author is a Googler, not sure why the CLA check is complaining. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
I found a bug within matCheckbox. I added a disabled class to the checkbox based on a method call. When disabled, the checkbox had class disabled and therefore had grey css etc, but if it was still clicked on, it had a click event which added a disabled class to the input within the checkbox. When the disabled class was removed from the outer matCheckbox, the disabled class remained on the input, so even though the checkbox appeared not to be disabled, it couldn't accept any more input.
Issue Number: 9763
What is the new behavior?
Clicking on a disabled checkbox should not change it in any way.
Does this PR introduce a breaking change?
Other information